package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	goSscan()
}

func goSscan() {
	var name = "ss   ss"
	var name1 string
	var name2 string
	fmt.Sscan(name, &name1, &name2)
	fmt.Println(name1, name2)
}

func goFscan() {
	var name string
	fmt.Fscan(os.Stdout, &name)
	fmt.Println(name)
}

func goBufio() {
	reader := bufio.NewReader(os.Stdout) // 从标准输入生成读对象
	fmt.Println("请输入内容")
	readString, _ := reader.ReadString('\n')
	strings.TrimSpace(readString)
	fmt.Printf("%#v", readString)
}

func goScanln() {
	var (
		name string
		age  int
	)
	fmt.Scanln(&name, &age)
	fmt.Printf("扫描结果：name：%s，age：%d", name, age)
}

func goScanf() {
	var (
		name string
		age  int
	)
	fmt.Scanf("1+%s 2+%d", &name, &age)
	fmt.Printf("扫描结果：name:%s,age:%d", name, age)
}

func goScan() {
	var (
		name string
		age  int
	)
	fmt.Scan(&name, &age)
	fmt.Printf("扫描结果 name:%s age:%d\n", name, age)
}

func goSprint() {
	s1 := fmt.Sprint("沙河小王子")
	name := "沙河小王子"
	age := 18
	s2 := fmt.Sprintf("name:%s,age:%d", name, age)
	s3 := fmt.Sprintln("沙河小王子")
	fmt.Println(s1, s2, s3)
}

func goFprint() {
	fmt.Fprintln(os.Stdout, "向标准输出写入内容")
	file, err := os.OpenFile("./xx.txt", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0664)
	if err != nil {
		fmt.Println("打开文件出错，err：", err)
		return
	}
	name := "沙河小王子"
	fmt.Fprintf(file, "往文件中写入信息：%s", name)
}
